package com.design.design.pattern.structural.proxy.selfPractice.cglibdynamic;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * 使用 cglib 实现动态代理
 * 要增强的逻辑 类似于aspect
 * @author TomDragon
 */
public class MethodInterceptorDemo implements MethodInterceptor {

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        // 增强逻辑
        System.out.println("before in cglib");
        // 调用原来的方法
        Object o1 = methodProxy.invokeSuper(o, objects);
        // 增强逻辑
        System.out.println("after in cglib");
        return o1;
    }
}
